<% layout('/layout/default.html', {title: '用户管理', libs: ['validate','icheck']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa fa-sitemap"></i> 用户添加
			</div>
		</div>
		
		<#form:form id="inputForm" model="${user}" class="form-horizontal" action="${ctx}/sys/user/save" method="post">
			<div class="box-body">
				<#form:hidden path="id"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="用户名">
								<span class="required" aria-required="true">*</span> 用户名: <i class="fa icon-question hide"></i>
							</label>
							<div class="col-sm-8">
								<#form:input path="name" maxlength="50" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="工号">
								<span class="required" aria-required="true">*</span> 工号: <i class="fa icon-question hide"></i>
							</label>
							<div class="col-sm-8">
								<#form:input path="no" class="form-control required" maxlength="50" />
							</div>
						</div>
					</div>
				</div>
				
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="登录名">
								<span class="required" aria-required="true">*</span>登录名: <i class="fa icon-question hide"></i>
							</label>
							<div class="col-sm-8">
								<%if(!user.isNewRecord){%>
									<input id="oldLoginName" name="oldLoginName" type="hidden" value="${user.loginName}" />
								<%}%>
								<#form:input path="loginName" maxlength="50" class="form-control required ${user.isNewRecord?'userName':''}"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="用户类型">
								<span class="required" aria-required="true">*</span> 用户类型: <i class="fa icon-question hide"></i>
							</label>
							<div class="col-sm-8">
								<#form:select path="userType" name="label" data="getDictList:sys_user_type"  class="form-control" />
							</div>
						</div>
					</div>
				</div>
				
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="归属公司">
								<span class="required" aria-required="true">*</span> 归属公司: <i class="fa icon-question hide"></i>
							</label>
							<div class="col-sm-8">
								<#form:treeselect id="companyId" name="company.id" value="${user.company.id!}" labelName="user.company.parentName" 
										labelValue="${user.company.name!}" title="公司" url="/sys/office/treeData?type=1" notAllowSelectParent="true" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="归属部门">
								<span class="required" aria-required="true">*</span> 归属部门: <i class="fa icon-question hide"></i>
							</label>
							<div class="col-sm-8">
								<#form:treeselect id="officeId" name="office.id" value="${user.office.id!}" labelName="user.office.parentName" 
								labelValue="${user.office.name!}" title="部门" url="/sys/office/treeData?type=2" notAllowSelectParent="true" />
							</div>
						</div>
					</div>
				</div>
				
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="是否允许登录">
								<span class="required" aria-required="true">*</span> 是否允许登录: <i class="fa icon-question hide"></i>
							</label>
							<div class="col-sm-8">
								<#form:select path="loginFlag" name="label"  data="getDictList:yes_no" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="邮箱">
								邮箱:
							</label>
							<div class="col-sm-8">
								<#form:input path="email" maxlength="50" class="form-control email"/>
							</div>
						</div>
					</div>
				</div>
				
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="电话">
								电话:
							</label>
							<div class="col-sm-8">
								<#form:input path="phone" maxlength="50" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="手机">
								手机:
							</label>
							<div class="col-sm-8">
								<#form:input path="mobile" class="form-control" maxlength="50" />
							</div>
						</div>
					</div>
				</div>
				
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="用户角色">
								<span class="required" aria-required="true">*</span>用户角色:<i class="fa icon-question hide"></i>
							</label>
							<div class="col-sm-8">
								<#form:checkboxes path="roleIdList" data="${user.roleIdList}" items="${allRoles}" itemLabel="name" itemValue="id" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="上次登录">
								备注:
							</label>
							<div class="col-sm-8">
								<#form:textarea path="remarks" rows="3" cols="32"  class="form-control"></#form:textarea>
							</div>
						</div>
					</div>
				</div>
				
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
					<% if (hasPermi('sys:user:edit')){ %>
						<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> 保 存</button>
					<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="window.parent.closeCurrentTabPage();"><i class="fa fa-reply-all"></i> 关 闭</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
$("#inputForm").validate({
	rules: {
		loginName: {remote: "${ctx}/sys/user/checkLoginName?oldLoginName=" + encodeURIComponent('${user.loginName}')}
	},
	messages: {
		loginName: {remote: "用户登录名已存在"},
		confirmNewPassword: {equalTo: "输入与上面相同的密码"}
	},
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == 'true'){
				window.parent.closeCurrentTabPage(window.parent.refreshTab);
			}
		});
	},
	errorPlacement: function(error, element) {
		//js.showMessage("输入有误，请先更正。");
		//$("#messageBox").text("输入有误，请先更正。");
		/* if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
			error.appendTo(element.parent().parent());
		} else {
			error.insertAfter(element);
		} */
	}
});
</script>